public class Solution {
    public static boolean canJump(int[] nums) {
        int left = 0, right = 0, maxPos = 0, n = nums.length;
        while(left <= right){
            for(int i = left; i <= right; i++){
                maxPos = Math.max(maxPos, i + nums[i]);
            }
            if(maxPos >= n - 1){
                return true;
            }
            left = right + 1;
            right = maxPos;

        }

        return false;
    }

    public static void main(String[] args) {
        int[] nums = {2,3,1,1,4};
        System.out.println(canJump(nums));
    }
}
